package com.fan.shop.businesslogic;

import org.apache.log4j.Logger;

import com.fan.shop.domain.Store;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.StoreService;

public class StoreUpdateProcess extends ProcExec<Integer> {

	private String storeCode;
	private String storeName;
	private String address;
	private int suspended;
	private static Logger logger = Logger.getLogger(StoreUpdateProcess.class);
	private StoreService storeService;

	public String getStoreCode() {
		return storeCode;
	}

	public void setStoreCode(String storeCode) {
		this.storeCode = storeCode;
	}

	public String getStoreName() {
		return storeName;
	}

	public void setStoreName(String storeName) {
		this.storeName = storeName;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getSuspended() {
		return suspended;
	}

	public void setSuspended(int suspended) {
		this.suspended = suspended;
	}

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		StoreUpdateProcess.logger = logger;
	}

	public StoreService getStoreService() {
		return storeService;
	}

	public void setStoreService(StoreService storeService) {
		this.storeService = storeService;
	}

	@Override
	public Integer processImpl() {
		if (storeService.hasStore(storeCode)) {
			Store store = storeService.getStore(storeCode);
			store.setAddress(address);
			store.setStoreName(storeName);
			store.setSuspended(suspended);
			storeService.updateStore(store);
			return ShopGlobalVariables.SUCCESS;
		} else {
			setErrorMessage("Store: " + storeCode + " doesn't exist!");
			return ShopGlobalVariables.FAILED;
		}
	}

}
